﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BurnSystems.Gpx
{
    /// <summary>
    /// Defines a boundingbox for points
    /// </summary>
    public class BoundingBox
    {
        /// <summary>
        /// Gets or sets the left position of the bounding box
        /// </summary>
        public double Left
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the right position of the bounding box
        /// </summary>
        public double Right
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the top position of the bounding box
        /// </summary>
        public double Top
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the bottom position of the bounding box
        /// </summary>
        public double Bottom
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the width of the bounding box
        /// </summary>
        public double Width
        {
            get { return this.Right - this.Left; }
        }

        /// <summary>
        /// Gets the height of the bounding box
        /// </summary>
        public double Height
        {
            get { return this.Bottom - this.Top; }
        }

        /// <summary>
        /// Adds a point to the bounding box
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void Add(double x, double y)
        {
            this.Left = Math.Min(x, this.Left);
            this.Top = Math.Min(y, this.Top);

            this.Right = Math.Max(x, this.Right);
            this.Bottom = Math.Max(y, this.Bottom);
        }

        /// <summary>
        /// Adds a bounding box
        /// </summary>
        /// <param name="bb">Bounding box to be added</param>
        public void Add(BoundingBox bb)
        {
            // Adds upper left and lower right point
            this.Add(bb.Left, bb.Top);
            this.Add(bb.Right, bb.Bottom);
        }
    }
}
